var equipmentSingleKWHDayData = [];
var totalPage = 0;
var totalCnt = 0;
var lastheaderNameEN = undefined;
var dataList = [];
var myChart = "";

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	createTableHead("equipmentSingleKWHDayThead", equipmentSingleKWHDayTable, search);
	scrollTableSuspend("scrollBody", "equipmentSingleKWHDayTable", "equipmentSingleKWHDayTable1", "equipmentSingleKWHDayThead", "scrollHeight");
	selectDate("startDate");
	$("#startChargingTime").val(date2String(getSystemTime()));
	$ajaxList('chargingStation', getChargingStation, {BulidStatus: '3'});
	setTimeout(hideLoading, 500);
});
function getChargingStation(data) {
	var length = data.length;
	for (var i = 0; i < length; i++) {
		$("#chargingStationID").append("<option value='" + data[i].chargingStationID + "'>" + data[i].chargingStationName + "</option>");
	}
	$("#chargingStationID").attr('size', (length + 1) > 10 ? 10 : (length + 1));
}
function changeEquipmet(){
	var chargingStationID = $("#chargingStationID").val();
	$("#chargingStationID").attr('size', 0);
	if (chargingStationID) {
		$("#changeEquipment").show();
		$("#equipmentID").empty();
		$ajaxList('equipmentNo', getEquipmentNo, {"chargingStationID": chargingStationID});
	} else {
		$("#changeEquipment").hide();
		$("#equipmentID").empty();
	}
}
function getEquipmentNo(data) {
	var length = data.length;
	$("#equipmentID").append("<option value=''>请选择</option>");
	for (var i = 0; i < length; i++) {
		$("#equipmentID").append("<option value='" + data[i].equipmentID + "'>" + data[i].equipmentName + "</option>");
	}
	$("#equipmentID").attr('size', (length + 1) > 10 ? 10 : (length + 1));
}
function search(headerNameEN){
	$("#equipmentID").attr('size', 0);
	if($("#equipmentID").val() == ""){
		return;
	}
	if(lastheaderNameEN != headerNameEN){
		clearOrder(lastheaderNameEN);
		lastheaderNameEN = headerNameEN;
	}
	$ajax('searchEquipmentSingleKWHDay', 'equipmentSingleKWHDaySearch', searchEquipmentSingleKWHDay);
}
function searchEquipmentSingleKWHDay(data) {
	equipmentSingleKWHDayData = data && data.equipmentSingleKWHDayList || [];
	createTableBody("equipmentSingleKWHDayTbody", equipmentSingleKWHDayTable, equipmentSingleKWHDayData, false, true);
	changeEchart();
	setTimeout(hideLoading, 500);
}
function changeEchart(){
	$("#histogram").empty();
	if(equipmentSingleKWHDayData.length == 0){
		$("#contenter").attr("hidden",true);
		return;
	}
	$("#contenter").attr("hidden",false);
	myChart = echarts.init(document.getElementById('histogram'));
	var theadName = "充电电量(KWH)";
    var option = {
            tooltip : {
            	trigger: 'axis',
            },
            xAxis: [
                {
                	type: 'time',
                	name: '充电时间',
                	min: $("#startChargingTime").val() + ' 00:00:00',
                	max: $("#startChargingTime").val() + ' 23:59:59',
                	splitNumber: 12,
                	axisLabel: {
                		formatter : function (params) {
                            var date = new Date(params);
                            data = date.getHours() + ':'
                            	+ date.getMinutes() + ':'
                            	+ date.getSeconds();
                            return data;
                        }
                	}
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: theadName
                }
            ],
            series: [
                {
                    name:theadName,
                    type:'bar',
                    barWidth:3,
                    itemStyle: {
                        normal : {
                            color: '#09be09',
                        }
                    },
                    data:(function () {
                        var d = [];
                        var len = 0;
                        while (len < equipmentSingleKWHDayData.length) {
                            d.push([
                                timeStamp2String(equipmentSingleKWHDayData[len].startChargingDTTM),
                                equipmentSingleKWHDayData[len].totalChargingKWH
                            ]);
                            len++;
                        }
                        return d;
                    })()
                }
            ]
        };
    myChart.setOption(option);
}
